package ${basePackage}.web;
import ${basePackage}.entity.${modelNameUpperCamel};
import ${basePackage}.service.${modelNameUpperCamel}Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import com.lz.yz.base.entity.ReturnValue;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by ${author} on ${date}.
*/
@RestController
@RequestMapping("${baseRequestMapping}")
public class ${modelNameUpperCamel}Controller {
    @Resource
    private ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

    @PostMapping
    public ReturnValue add(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}Service.save(${modelNameLowerCamel});
        return ReturnValue.generateTrueReturnValue();
    }

    @DeleteMapping("/{id}")
    public ReturnValue delete(@PathVariable Integer id) {
        ${modelNameLowerCamel}Service.deleteById(id);
        return ReturnValue.generateTrueReturnValue();
    }

    @PutMapping
    public ReturnValue update(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}Service.update(${modelNameLowerCamel});
        return ReturnValue.generateTrueReturnValue();
    }

    @GetMapping("/{id}")
    public ReturnValue detail(@PathVariable Integer id) {
        ${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.findById(id);
        return ReturnValue.generateTrueReturnValue(${modelNameLowerCamel});
    }

    @GetMapping
    public ReturnValue list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer size) {
        PageHelper.startPage(page, size);
        List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ReturnValue.generateTrueReturnValue(pageInfo);
    }
}
